package cn.iocoder.yudao.module.ai.service.trainingmodel;

import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import cn.iocoder.yudao.module.ai.controller.admin.trainingmodel.vo.*;
import cn.iocoder.yudao.module.ai.dal.dataobject.trainingmodel.TrainingModelDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.ai.dal.mysql.trainingmodel.TrainingModelMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 训练模型清单 Service 实现类
 *
 * @author gt
 */
@Service
@Validated
public class TrainingModelServiceImpl implements TrainingModelService {

    @Resource
    private TrainingModelMapper trainingModelMapper;

    @Override
    public Integer createTrainingModel(TrainingModelSaveReqVO createReqVO) {
        // 插入
        TrainingModelDO trainingModel = BeanUtils.toBean(createReqVO, TrainingModelDO.class);
        trainingModelMapper.insert(trainingModel);
        // 返回
        return trainingModel.getId();
    }

    @Override
    public void updateTrainingModel(TrainingModelSaveReqVO updateReqVO) {
        // 更新
        TrainingModelDO updateObj = BeanUtils.toBean(updateReqVO, TrainingModelDO.class);
        trainingModelMapper.updateById(updateObj);
    }

    @Override
    public void deleteTrainingModel(Integer id) {
        // 删除
        trainingModelMapper.deleteById(id);
    }


    @Override
    public TrainingModelDO getTrainingModel(Integer id) {
        return trainingModelMapper.selectById(id);
    }

    @Override
    public PageResult<TrainingModelDO> getTrainingModelPage(TrainingModelPageReqVO pageReqVO) {
        return trainingModelMapper.selectPageNotDraft(pageReqVO);
    }

    @Override
    public PageResult<TrainingModelDO> queryOwnModelDraft(TrainingModelPageReqVO pageReqVO) {
        pageReqVO
                .setCreator(SecurityFrameworkUtils.getLoginUserId() + "")
                .setStatus("0");
        return trainingModelMapper.selectPage(pageReqVO);
    }

}